package org.shopen.puremvc.view
{
	import flash.events.Event;
	
	import org.puremvc.as3.patterns.mediator.Mediator;
	import org.shopen.puremvc.ApplicationConstants;
	import org.shopen.puremvc.view.components.HeaderControlBar;

	public class HeaderControlBarMediator extends Mediator
	{
		public static const NAME : String = "HeaderControlBarMediator";
		
		public function HeaderControlBarMediator(viewComponent:Object=null)
		{
			super(HeaderControlBarMediator.NAME, viewComponent);
		}
		
		override public function onRegister() : void
		{
			addListeners();
		}
		
		protected function get controlBar() : HeaderControlBar
		{
			var result : HeaderControlBar = viewComponent as HeaderControlBar;
			return result;
		}
		
		private function addListeners() : void
		{
			controlBar.addEventListener(HeaderControlBar.CLICK_ABOUT, clickAboutListener);
			controlBar.addEventListener(HeaderControlBar.CLICK_HELP, clickHelpListener);
		}
		
		private function clickAboutListener(e : Event) : void
		{
			if (e.type == HeaderControlBar.CLICK_ABOUT)
			{
				sendNotification(ApplicationConstants.SHOW_ABOUT);
			}
		}
		
		private function clickHelpListener(e : Event) : void
		{
			if (e.type == HeaderControlBar.CLICK_HELP)
			{
				sendNotification(ApplicationConstants.SHOW_HELP);
			}
		}
	}
}